package com.tuling.concurrent;

public class VolatileVisibilityTest {

//    private static boolean initFlag = false;
    private static volatile boolean initFlag = false;

    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("waiting data...");
                while (!initFlag) {
                }
                System.out.println("======success");
            }
        }).start();

        Thread.sleep(2000);

        new Thread(new Runnable() {
            @Override
            public void run() {
                prepareDate();
            }
        }).start();
    }

    public static void prepareDate() {
        System.out.println("prepareDate data...");
        initFlag = true;
        System.out.println("prepare Date end...");
    }
}
